package com.zlx.guguanjia.mapper;


import com.zlx.guguanjia.entity.SysResource;
import com.zlx.guguanjia.mapper.provider.SysResourceSqlProvider;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import tk.mybatis.mapper.common.Mapper;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@org.apache.ibatis.annotations.Mapper
public interface SysResourceMapper extends Mapper<SysResource> {
    @Select("SELECT sr.* FROM sys_role_resource srr " +
            " LEFT JOIN" +
            " sys_resource sr ON " +
            " srr.resource_id = sr.id " +
            " WHERE " +
            " srr.role_id = #{rid}")
    List<SysResource> selectResourceByRid(Long rid);

    /**
     * @Author 周罗校
     * @Description 根据用户id查询权限菜单
     @Param [uid]
      * @return java.util.List<com.zlx.guguanjia.entity.SysResource>
     * @Date 2020.11.06 11:09:27
     **/
    @Select("SELECT DISTINCT " +
            "sre.id, " +
            "sre.`name`, " +
            "sre.common, " +
            "sre.icon, " +
            "sre.sort, " +
            "sre.parent_id, " +
            "sre.type, " +
            "sre.url, " +
            "sre.description, " +
            "sre.`status`, " +
            "sre.parent_ids, " +
            "sre.create_date, " +
            "sre.update_date, " +
            "sre.create_by, " +
            "sre.update_by, " +
            "sre.del_flag, " +
            "sre.permission_str  " +
            "FROM " +
            "sys_role_resource AS srr, " +
            "sys_resource AS sre, " +
            "sys_user AS su, " +
            "sys_user_role AS sur  " +
            "WHERE " +
            "sre.del_flag = 0  " +
            "AND su.id = #{uid}  " +
            "AND sre.type = 0  " +
            "AND srr.resource_id = sre.id  " +
            "AND srr.role_id = sur.role_id  " +
            "AND sur.user_id = su.id  " +
            "ORDER BY " +
            "sre.sort ASC")
    List<SysResource> selctByUid(Long uid);
    
    
    @Select("SELECT * FROM sys_resource  " +
            "WHERE " +
            "del_flag =0  " +
            "AND type =0 " +
            "AND common = 0 " +
            "AND url <> ''")
    List<SysResource> selectResource();

    @Select("SELECT * FROM sys_resource  " +
            "WHERE " +
            "del_flag =0 " +
            "AND type =0 " +
            "ORDER BY sort")
    List<SysResource> selectParentMenuSources();

    @SelectProvider(type = SysResourceSqlProvider.class,method ="selectMenuSources")
    List<SysResource> selectMenuSources(Map<String,Object> map);
}